#ifndef TC_FORCEINDEX_HPP
#define TC_FORCEINDEX_HPP

/** \file ForceIndex.hpp
 * Definition of the ForceIndex function template.
 *
 * (C) Copyright 2003-2006 by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: ForceIndex.hpp 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */

#include "TA.hh"


namespace TC {

  //! Force Index calculator
  TC_EXPORT template <typename InputIterator,
                      typename OutputIterator,
                      class Adaptor>
  void ForceIndex(InputIterator fromPos,
                  InputIterator fromEnd,
                  OutputIterator toPos,
                  const Adaptor adaptor)
  {
    // Today's close
    register typename Adaptor::Price_t cls, ycls;
    // Yesterday's close
    ycls = adaptor.cls(*fromPos++);
    // Force Index value
    register TAfp_t fi = 0.0;

    *toPos++ = fi; // First value is zero
    for(; fromPos!=fromEnd; ++fromPos) {
      // Get today's close
      cls = adaptor.cls(*fromPos);
      // Calc. force index
      fi = (cls - ycls) * adaptor.vol(*fromPos);
      // Store yesterday's close
      ycls = cls;
      // Store the force index
      *toPos++ = fi;
    }

  }


} // end namespace


#endif /* Include guard */
